package com.example.administrator.zkdemo.adapter;

/**
 * Created with Android Studio.
 * 描述: ${DESCRIPTION}
 * Date: 2018/11/20
 * Time: 16:34
 *
 * @author 晏琦云
 * @version ${VERSION}
 */

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.zkdemo.model.ZKSettingBean;

import java.util.List;

public class ZKSettingAdapter extends RecyclerView.Adapter<ZKSettingAdapter.ViewHolder> {
    private Context mContext;
    private List<ZKSettingBean> mData;
    private ItemClick mItemClick;

    public ZKSettingAdapter(Context paramContext, List<ZKSettingBean> paramList, ItemClick paramItemClick) {
        this.mContext = paramContext;
        this.mData = paramList;
        this.mItemClick = paramItemClick;
    }

    public int getItemCount() {
        return this.mData.size();
    }

    public ViewHolder onCreateViewHolder(ViewGroup paramViewGroup, int paramInt) {
        return new ViewHolder(LayoutInflater.from(paramViewGroup.getContext()).inflate(2131427398, paramViewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        final ZKSettingBean localZKSettingBean = this.mData.get(i);
        viewHolder.setBackground(localZKSettingBean.getBg());
        viewHolder.setIcon(localZKSettingBean.getIcon());
        viewHolder.setTitle(localZKSettingBean.getTitle());
        viewHolder.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramView) {
                if (ZKSettingAdapter.this.mItemClick != null)
                    ZKSettingAdapter.this.mItemClick.onClick(localZKSettingBean.getTitle());
            }
        });
    }

    public static abstract interface ItemClick {
        public abstract void onClick(int paramInt);
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_icon;
        private LinearLayout ll_item;
        private TextView tv_title;

        ViewHolder(View localView) {
            super(localView);
            this.ll_item = localView.findViewById(2131296451);
            this.tv_title = localView.findViewById(2131296635);
            this.iv_icon = localView.findViewById(2131296432);
        }

        @SuppressLint({"NewApi"})
        void setBackground(int paramInt) {
            this.ll_item.setBackground(ZKSettingAdapter.this.mContext.getDrawable(paramInt));
        }

        @SuppressLint({"NewApi"})
        void setIcon(int paramInt) {
            this.iv_icon.setImageDrawable(ZKSettingAdapter.this.mContext.getDrawable(paramInt));
        }

        void setOnClickListener(View.OnClickListener paramOnClickListener) {
            this.ll_item.setOnClickListener(paramOnClickListener);
        }

        void setTitle(int paramInt) {
            this.tv_title.setText(paramInt);
        }
    }
}
